package mark_2.io;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        ImageManager imageManager = new ImageManager();
        Scanner scanner = new Scanner(System.in);
        boolean isRunning = true;

        System.out.println("===== 网络图片下载与管理系统 =====");

        while (isRunning) {
            System.out.println("\n请选择操作：");
            System.out.println("1. 下载图片");
            System.out.println("2. 列出所有已下载图片");
            System.out.println("3. 搜索图片");
            System.out.println("4. 退出");
            System.out.print("输入选项(1-4)：");

            int choice = scanner.nextInt();
            scanner.nextLine(); // 消耗输入后的换行符

            switch (choice) {
                case 1:
                    System.out.print("请输入图片URL：");
                    String url = scanner.nextLine();
                    if (imageManager.downloadImage(url)) {
                        System.out.println("图片下载成功！");
                    } else {
                        System.out.println("图片下载失败～");
                    }
                    break;
                case 2:
                    imageManager.listImages();
                    break;
                case 3:
                    System.out.print("请输入要搜索的图片名：");
                    String name = scanner.nextLine();
                    String path = imageManager.searchImage(name);
                    if (path != null) {
                        System.out.println("找到图片，路径：" + path);
                    } else {
                        System.out.println("未找到该图片～");
                    }
                    break;
                case 4:
                    isRunning = false;
                    System.out.println("感谢使用，再见～");
                    break;
                default:
                    System.out.println("无效选项，请重新输入～");
            }
        }
        scanner.close();
    }
}

